<DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <base href="${rc.contextPath}/">
    <title>优惠信息</title>
<#include "/commons/stylesheets.ftl">
    <link href="jquery-select2/select2.min.css" rel="stylesheet">
    <link href="/layer/skin/layer.css" rel="stylesheet">
</head>

<body >
<div class="container-fluid">

    <div class="row">

                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="bindForm" action = "/bindcoupon/binduser" method = "post">
                        <div class="form-group">
						    <label class="col-xs-2 control-label">优惠名称：</label>
						    <div class="col-xs-10">
						        <input type="hidden" name="id" value="${coupon.id!}"/>
						        <input name="couponName" minlength="2" value="${coupon.couponName!}" type="text" class="form-control" disabled="" required="" aria-required="true">
						    </div>
						</div>
						
						
						<div class="form-group">
						    <label class="col-xs-2 control-label">优惠类型：</label>
						    <div class="col-xs-10">
						        <select name="couponType" value="${coupon.couponType!}" disabled="" class="form-control">
						            <option value="1">定时定向</option>
						        </select>
						    </div>
						</div>
						
					
						<div class="form-group">
                        	<label class="col-xs-2 control-label">适用用户：</label>
                            <div class="col-xs-1">
                                <button type="button" class="btn btn-primary" onclick="openDialog('/customerVehicle/userSelect','用户查询',960,660)">选择</button>
                            </div>  
                            <div class="col-xs-9">
                            	<input type="hidden" id="uids" value="" name="uids"/>
                            	<input type="hidden" id="utype" value="" name="utype"/>
                                <input id="userName" minlength="2"  type="text" class="form-control" disabled="" required="" aria-required="true">
                            </div>             
                        </div>
                        
                        <div class="form-group">
                        	<label class="col-xs-2 control-label">适用商户：</label>
                            <div class="col-xs-1">
                                <button type="button" class="btn btn-primary" onclick="openDialog('/business/select','商户查询',960,660)">选择</button>
                            </div>  
                            <div class="col-xs-9">
                            	<input type="hidden" id="buids" value="" name="buids"/>
                                <input id="businessUserNames"  minlength="1"  type="text" class="form-control" disabled=""	 required="" aria-required="true">
                            </div>             
                        </div>       
						
						<div class="form-group">
						    <label class="col-xs-2 control-label">有效期起：</label>
						    <div class="col-xs-10">
						        <input  class="form-control" id="start" name="validBegin" value="${coupon.validBegin!?string("yyyy-MM-dd")}" disabled="" required="" aria-required="true" >
						    </div>
						</div>
						
						<div class="form-group">
						    <label class="col-xs-2 control-label">有效期止：</label>
						    <div class="col-xs-10">
						        <input class="form-control" id="end" name="validEnd" value="${coupon.validEnd!?string("yyyy-MM-dd")}" disabled="" required="" aria-required="true" >
						    </div>
						</div>
						
						<div class="form-group">
						    <label class="col-xs-2 control-label">发送内容：</label>
						    <div class="col-xs-10">
						        <input class="form-control" id="content" name="content" value="尊敬的会员，您活动{店铺}的优惠券，编号{券号}，使用时间{有效期}" required="" aria-required="true" >
						    </div>
						</div>
						
						<div class="form-group">
						    <label class="col-xs-2 control-label">发送方式：</label>
                            
                            <div class="col-sm-10">
                                    
                                    <div class="radio">
                                        <label>
                                            <input type="radio" checked="" value="1" id="option1" name="sendType">推送消息</label>
                                        <label>
                                   			 <input type="radio" value="2" id="options2" name="sendType">短信</label>
                            		</div>
                             </div>
						</div>
						
						<div class="form-group">
						    <label class="col-xs-2 control-label">激活时间：</label>
                            
                            <div class="col-sm-10">
                                    
                                    <div class="radio">
                                        <label>
                                            <input type="radio" class="radioItem" checked="checked" onclick='check3(this)' value="1" id="option3" name="activeType">立即激活</label>
                                        <label>
                                   			 <input type="radio" value="2" class="radioItem" onclick='check4(this)' id="option4" name="activeType">定时激活 
                                   		</label>
                                   		<label>
                                   			 <input id="activeTime" value='' minlength="2" name="activeTime" disabled  type="text" class="form-control" >
                                   		</label>
                            		</div>
                            		
                             </div>
						</div>

                        <div class="form-group">
                            <div class="col-xs-10 col-xs-offset-2">
                                <button class="btn btn-primary" type="submit">保存</button>
                            </div>
                        </div>
                    </form>
                </div>


    </div>

</div>
<#include "/commons/scripts.ftl">

<script src="jquery-select2/select2.min.js"></script>
<script src="layer/layer.js"></script>
<script src="js/app.js"></script>
<script src="js/plugins/layer/laydate/laydate.js"></script>

<script src="js/plugins/validate/jquery.validate.min.js"></script>
<script src="js/plugins/validate/messages_zh.min.js"></script>
<script type="text/javascript">
    
	var start = {
            elem: "#start",
            format: "YYYY-MM-DD hh:mm:ss",
            min: laydate.now(),
            max: "2099-06-16 23:59:59",
            istime: true,
            istoday: false,
            choose: function (a) {
                end.min = a;
                end.start = a
            }
        };
        var end = {
            elem: "#end",
            format: "YYYY-MM-DD hh:mm:ss",
            min: laydate.now(),
            max: "2099-06-16 23:59:59",
            istime: true,
            istoday: false,
            choose: function (a) {
                start.max = a
            }
        };
        
        var activeTime = {
            elem: "#activeTime",
            format: "YYYY-MM-DD hh:mm:ss",
            min: laydate.now(),
            max: "2099-06-16 23:59:59",
            istime: true,
            istoday: false,
            choose: function (a) {
                start.max = a
            }
        };
        laydate(start);
        laydate(end);
        laydate(activeTime);
        
        function setUser(uids,names,utype){
        	$("#userName").val(names);
        	$("#uids").val(uids);
        }
        
        function setBusinessUser(uids,names){
        	$("#businessUserNames").val(names);
        	$("#buids").val(uids);
        }
        
        function check3(obj){
        	$(obj).attr("checked","checked");
        	$("#option4").removeAttr("checked");
        }
        
        function check4(obj){
        	$(obj).attr("checked","checked");
        	$("#option3").removeAttr("checked");
        }
        
        
            
        $.validator.setDefaults({
            highlight:function(a){
                $(a).closest(".form-group").removeClass("has-success").addClass("has-error")
            },
            success:function(a){a.closest(".form-group").removeClass("has-error").addClass("has-success")},
            errorElement:"span",
            errorPlacement:function(a,b){
                if(b.is(":radio")||b.is(":checkbox")){
                    a.appendTo(b.parent().parent().parent())
                }else{
                    a.appendTo(b.parent())
                }
            },
            errorClass:"help-block m-b-none",
            validClass:"help-block m-b-none"
        });
        
        $().ready(function(){
        
        	$("#commentForm").validate();
            var a="<i class='fa fa-times-circle'></i> ";
            
        	console.log("ready in ");
            $("#bindForm").validate({
            	submitHandler : function(form) {
            	
                   
                    if($("#uids").val() == '') {
                        layer.msg('请选择用户');
                        return false;
                    }
                    
                    if($("#buids").val() == '') {
                        layer.msg('请选择商户');
                        return false;
                    }
                    
                    if($("#option4").attr("checked") == "checked") {
                    	if($("#activeTime").val() == '') {
                    		layer.msg('请选择激活时间');
                    		 return false;
                    	}
                    }
                    
                    form.submit();
                }  
            });
            
            $(".radioItem").change( function() {
                var val=$('input:radio[name="activeType"]:checked').val();
                 if(val == "2"){
                     $("#activeTime").rules("remove");
                     $("#activeTime").rules("add", { required: true});
                     $('#activeTime').attr("disabled",false);
                 } else {
                     $('#activeTime').val("");
                     $("#activeTime").rules("remove");
                     $("#activeTime").closest('.form-group').removeClass('has-error');
                     $('#activeTime').attr("disabled",true);
                 }
              });
            
         });
 
</script>



</body>

</html>